/**
 * @summary 频道模块
 * @author 陈俊可
 * @description
 *      这是个菜鸡
 */

import * as suggestionApi from '@/api/suggestion';
export default {
  namespaced: true,
  state: {
    // 联想建议列表
    suggestionList: [],
    // 搜索结果列表
    searchResult: [],
  },

  mutations: {
    SET_SUGGESTION_LIST(state, newValue) {
      state.suggestionList = newValue;
    },

    SET_SEARCH_RESULT(state, newValue) {
      state.searchResult = newValue;
    },
  },

  actions: {
    async updateSuggestionList({ commit }, value) {
      // 发请求
      const res = await suggestionApi.getSuggestionList(value);
      // 拿到数据
      // 把数据传给mutation
      // 把mutation改数据
      commit('SET_SUGGESTION_LIST', res);
    },

    async updateSearchResult({ commit }, value) {
      // 发请求
      const res = await suggestionApi.getSearchResult(value);
      // 拿到数据
      // 把数据传给mutation
      // 把mutation改数据
      commit('SET_SEARCH_RESULT', res);
    },
  },
}
